/*
 *      Created on: Mar 8, 2011
 *      Author: topcoder
 */
#include <Square.h>
#include <MathAlgorithm.h>
#include <math.h>

namespace
{
    const double MIN_SIDE_LENGTH = 0;
    const double MAX_SIDE_LENGTH = 75;
}

Square::Square(double length)
{
    length_m = getTruncateValue(length, 2);
}

double Square::setLength(double length)
{
    double tempLength = getTruncateValue(length, 2);

    if(isParameterValid(tempLength, MIN_SIDE_LENGTH, MAX_SIDE_LENGTH))
    {
        length_m = tempLength;
    }
}

bool Square::isShapeValid() const
{
    return isParameterValid(length_m, MIN_SIDE_LENGTH, MAX_SIDE_LENGTH);
}

double Square::calculateArea() const
{
    return (isShapeValid())?(getRoundValue(pow(length_m, 2), 2)):0;
}

double Square::calculatePerimeter() const
{
    return (isShapeValid())?(getRoundValue(4 * length_m, 2)):0;
}



